Repository navigation
fix(updater): validate cached update filenames (v26 backport of #10115) - #10300
Conversation
(cherry picked from commit 4ca053b) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BuQiaJ7WL1k8vji2pHkSHp
🦋 Changeset detectedLatest commit: d7007a6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. Because this is a path-traversal fix in cached-update file resolution, a human look would still be worthwhile.
What was reviewed:
- The new
fileNamevalidation (typeof === "string", non-empty,path.basename(fileName) === fileName) and its use inpath.join(cacheDirForPendingUpdate, cachedFileName). - The new tests covering a missing
fileNameand a../outside.exetraversal attempt, both rejected with cache cleanup. - Checked whether a literal
".."value still passes the basename check (it does, sincepath.basename("..") === ".."), but exploiting it also requires the cachedsha512to already match the genuine expected update hash, the same constraint the upstream fix (#10115) this backports shares.
Extended reasoning...
The diff is a 3-line security fix in packages/electron-updater/src/DownloadedUpdateHelper.ts (plus a changeset and two new vitest cases) that validates cachedInfo.fileName is a non-empty plain basename before using it in path.join, closing a path-traversal read of a corrupted/attacker-controlled update-info.json; it is a straightforward backport of an already-merged upstream PR (#10115) with added test coverage. It touches security-sensitive path-resolution logic, so per guidelines it is not auto-approved even though no bugs were found; I additionally confirmed a literal ".." value still passes the new basename check (path.basename("..") === ".."), though exploiting it would also require the cached sha512 to already equal the genuine expected hash, matching the same residual property of the original upstream fix.
Requested via Slack thread
This backports #10115 by @OskarEichler to v26. It makes
DownloadedUpdateHelpertreat a cachedupdate-info.jsonas corrupted, and clean the pending cache, when itsfileNameis missing, empty, or not a plain basename (for example../outside.exe), so a cached update can no longer be resolved outside the pending update directory. For v26 the source change keeps the branch's namedpathExistsimport from fs-extra, and the two new tests were ported into v26's flatdownloadedUpdateHelperTest.tslayout, which imports fromelectron-updater/out/...and usesmkdtempinstead of the mastertmpDirfixture. The original patch changeset for electron-updater is kept. Locally the updater test file passes 12/12, and the two new tests fail without the source change.🤖 Generated with Claude Code
https://claude.ai/code/session_01BuQiaJ7WL1k8vji2pHkSHp
Generated by Claude Code